package com.miracle9.game.server.message;

import org.apache.log4j.Logger;
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.SocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.net.InetSocketAddress;

//@Component
public class MainServerTest {
    private Logger logger = Logger.getLogger(MainServerTest.class);


    private SocketAcceptor acceptor = new NioSocketAcceptor();
    private DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();

    private int bindPort = 6992;
    @PostConstruct
    public void init(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                logger.info("xs start 111111111111111.....");
                acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
                acceptor.getFilterChain().addLast(
                        "codec",
                        new ProtocolCodecFilter(new MyCodecFactory1()));
                acceptor.setHandler(new XsSocketHandlerTest());
                try {
                    acceptor.bind(new InetSocketAddress(bindPort));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

}
